package com.easy.frame.common.mq.rabbit.confirm;

import com.easy.frame.common.redis.RedisUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;

import javax.annotation.Resource;

/**
 * @author 86131
 */
@Slf4j
public class ConfirmCallBack implements RabbitTemplate.ConfirmCallback {

    @Resource
    //private BrokerMessageLogMapper brokerMessageLogMapper;

    @Override
    public void confirm(CorrelationData correlationData, boolean ack, String cause) {
        log.info("correlationData:========>{}", correlationData != null ? correlationData.getId() : null);
        log.info("ack:================{}", ack);
        String messageId = correlationData.getId();
        if (ack) {
            //如果confirm返回成功 则进行更新
            //brokerMessageLogMapper.changeBrokerMessageLogStatus(messageId, RabbitConstants.ORDER_SEND_SUCCESS, new Date());
            RedisUtil.getInstance().del(correlationData.toString());
            System.out.println("mq生产端消息已经成功投递到了broker,更新我们消息日志表");
        } else {
            System.out.println("mq生产端没有被broker ack,原因:{}");
        }
    }
}
